package com.skycan.plc.adapter.config;

import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * MQTT配置
 */
@Getter
public class MqttConfig {
    private static final Logger logger = LoggerFactory.getLogger(MqttConfig.class);
    private static final MqttConfig INSTANCE = new MqttConfig();

    // MQTT服务器地址
    private String brokerUrl;
    // MQTT客户端ID
    private String clientId;
    // MQTT用户名
    private String username;
    // MQTT密码
    private String password;
    // 数据上报主题
    private String dataTopic;
    // 命令订阅主题
    private String commandTopic;

    private MqttConfig() {
        initConfig();
    }

    public static MqttConfig getInstance() {
        return INSTANCE;
    }

    /**
     * 初始化MQTT配置
     */
    private void initConfig() {
        AppConfig appConfig = AppConfig.getInstance();

        brokerUrl = appConfig.getProperty("mqtt.broker.url", "tcp://localhost:1883");
        clientId = appConfig.getProperty("mqtt.client.id", "plc-adapter");
        username = appConfig.getProperty("mqtt.username", "admin");
        password = appConfig.getProperty("mqtt.password", "public");
        dataTopic = appConfig.getProperty("mqtt.data.topic", "skycan/data");
        commandTopic = appConfig.getProperty("mqtt.command.topic", "skycan/command");

        logger.info("MQTT配置初始化完成: brokerUrl={}, clientId={}, dataTopic={}, commandTopic={}",
                brokerUrl, clientId, dataTopic, commandTopic);
    }
}